/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package testing;
import org.mockito.ArgumentMatcher;
import org.mockito.Mockito;

import java.util.List;

import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.*;

public class MockitoSimpleDemoTest10 {

    public static void main(String[] args) {
        // arrange
        List<String> listMock = mock(List.class);
        when(listMock.get(anyInt())).thenReturn("odd");
        when(listMock.get(evenInt())).thenReturn("even");
        // act
        listMock.add("hello");
        listMock.get(100);
        listMock.get(100);
        listMock.size();
        // assert
        verify(listMock).add("hello");
        verify(listMock, times(2)).get(100);
        Mockito.verifyNoMoreInteractions(listMock);
        Mockito.verifyZeroInteractions(listMock);
    }

    private static int evenInt() {
        return Mockito.intThat(
                new ArgumentMatcher<Integer>() {
                    @Override
                    public boolean matches(Object arg) {
                        return ((Integer) arg) % 2 == 0;
                    }
                });
    }
}
